'''
Created on Apr 24, 2012

@author: mekoda
'''
from main.cpu import CPU
from main.ioDevs import IO
from main.dataStructures import ProcessesQueue
from main.process import PCB, Instruction, Process, ProcessStatus, IOInstruction
from main.shortTermSchedulers import Scheduler_FirstComeFirstServe
from main.memory import MMU_ContinuousAssignment,BestAdjustment,PhysicalMemory
import unittest


class TestPlanners(unittest.TestCase):
    def setUp(self):
        self.memory = PhysicalMemory(5,BestAdjustment())
        self.mmu = MMU_ContinuousAssignment()
        self.ioQueue = IO()
        self.pcb1 =  PCB(3)
        self.pcb2 =  PCB(6)
        self.pcb3 =  PCB(7)
        self.instruction1 =  Instruction(ProcessStatus.CPU,1)
        self.instruction2 =  Instruction(ProcessStatus.CPU,2)
        self.instruction3 =  Instruction(ProcessStatus.CPU,3)
        self.instruction4 =  IOInstruction(4,'Printer')
        self.instruction5 =  Instruction(ProcessStatus.CPU,5)
        self.instruction6 =  IOInstruction(6,'Printer')
        self.instruction7 =  Instruction(ProcessStatus.CPU,7)
        self.instruction8 =  IOInstruction(3,'Printer')
        self.instruction9 =  IOInstruction(4,'Printer')
        self.instruction10=  Instruction(ProcessStatus.CPU,10)
        #------------------------------------------#
        self.process1 = Process(self.pcb1)
        self.process1.addInstruction(self.instruction1)
        self.process1.addInstruction(self.instruction2)
        self.process1.addInstruction(self.instruction3)
        self.process1.addInstruction(self.instruction4)
        #------------------------------------------#
        self.process2 = Process(self.pcb2)
        self.process2.addInstruction(self.instruction5)
        self.process2.addInstruction(self.instruction6)
        self.process2.addInstruction(self.instruction7)
        #------------------------------------------#
        self.process3 = Process(self.pcb3)
        self.process3.addInstruction(self.instruction8)
        self.process3.addInstruction(self.instruction9)
        self.process3.addInstruction(self.instruction10)
        self.process = ProcessesQueue()
        self.process.append(self.process1)
        self.process.append(self.process2)
        self.process.append(self.process3)
        self.cpu = CPU(self.process,self.ioQueue,self.mmu,self.memory)
        
        
#--------------------------------------------------------------------------#
#------------------TESTING: Scheduler_ByPriorities-------------------------#
#--------------------------------------------------------------------------#
    def setUp_Scheduler_FirstComeFirstServe(self):
        self.planner = Scheduler_FirstComeFirstServe(self.process,self.cpu,self.ioQueue)  
        
    #Elige al primer proceso en llegar a la cola de listos 
    def test_GetTheFirstProcess(self):
        self.setUp_Scheduler_FirstComeFirstServe()
        self.planner.manageAProcess()                            #Toma al primer proceso de la cola de listos y lo manda al Cpu
        self.assertEquals(self.cpu.currentProcess, self.process1)#El proceso que debe elegir es el proceso1
        
    
suite = unittest.TestLoader().loadTestsFromTestCase(TestPlanners)
unittest.TextTestRunner(verbosity=2).run(suite)